home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2008 April
/
PCWorld_2008-04_cd.bin
/
komercni software
/
miton
/
SystemMechanic7Pro.exe
/
{app}
/
smhtml.dll
/
1033
/
HTML
/
TABLE.JS
< prev
next >
Wrap
Text File
|
2008-01-24
|
6KB
|
218 lines
//This is an upgrade version of DataTable class
//***************** Object Class *******************************//
function Object(id)
{
this.ID= id || "";
this.Class = "";
this.Style = "";
this.Width = "";
this.Data = "";
this.Align = "";
this.Name = "Object";
}
//***************** End Object Class *******************************//
//***************** TD Class *******************************//
function TD(id)
{
this.base = Object;
this.base(id || "");
this.Render = __TDRender;
function __TDRender()
{
var content = "";
content += "<td class=\""+ this.Class +"\" ";
if (this.ID != "")
content += " id=\"" + this.ID + "\"";
if (this.Width != "")
content += " width=\"" + this.Width + "\"";
if (this.Align != "")
content += " align=\"" + this.Align + "\"";
content += ">\n";
content += this.Data;
content += "\n</td>\n";
return content;
}
//inherit from object
TD.prototype = new Object;
}
//***************** End TD Class *******************************//
//***************** TR Class *******************************//
function TR(id)
{
this.base = Object;
this.base(id || "");
this.TDs = new Array();
this.Add = __TRAdd;
this.Render = __TRRender;
function __TRAdd(ObjectTD)
{
this.TDs[this.TDs.length] = ObjectTD;
}
function __TRRender(RowClass)
{
var rowClass = RowClass || this.Class;
var content = "";
content += "\n<tr valign=\"top\" id='"+ this.ID +"' class=\""+ rowClass +"\">\n";
for ( x = 0; x < this.TDs.length; x++)
content += this.TDs[x].Render();
content += "\n</tr>\n";
return content;
}
//inherit from object
TR.prototype = new Object;
}
//***************** End TR Class *******************************//
//***************** Table Class *******************************//
function Table(id)
{
this.base = Object;
this.base(id);
this.ItemClass = "i";
this.AlternateItemClass = "a";
this.Border = "0";
this.Cellspacing = "0";
this.Cellpadding = "0";
this.TRs = new Array();
this.Add = __TableAdd;
this.Render = __TableRender;
this.Alternate = __TableRowAlternate;
this.IsRendered = __TableIsRendered;
this.ChangeClassInRowByIndex = __ChangeClassInRowByIndex;
this._ClientID = __ClientID;
//inherit from object
Table.prototype = new Object;
function __TableIsRendered()
{
return (Get(this._ClientID()) != null);
}
function __ClientID()
{
return "datatable_tbl_" + this.ID;
}
function __TableAdd(ObjectTR)
{
this.TRs[this.TRs.length] = ObjectTR;
var tbl = Get("datatable_tbl_" + this.ID);
if (tbl != null)
{
// The data table has already been rendered, so we need to manually
// add the data table item.
var tbody ;
var row ;
tbody = tbl.childNodes[0];
if(tbody.rows)
row = tbody.insertRow(tbody.rows.length); //ie
else
row = tbl.insertRow(tbl.childNodes.length ); //firefox
// adding the primary key to the table row 'id'
if(ObjectTR.ID != "") row.setAttribute('id', ObjectTR.ID );
if (ObjectTR.Class != "") row.className = ObjectTR.Class;
var cell = null;
for (var x = 0; x < ObjectTR.TDs.length; x++)
{
cell = row.insertCell(row.cells.length);
if (ObjectTR.TDs[x].ID != "") cell.setAttribute("id", ObjectTR.TDs[x].ID);
if (ObjectTR.TDs[x].Align != "") cell.setAttribute("align", ObjectTR.TDs[x].Align);
if (ObjectTR.TDs[x].Width != "") cell.setAttribute("width", ObjectTR.TDs[x].Width);
if (ObjectTR.TDs[x].Class != "") cell.className = ObjectTR.TDs[x].Class;
cell.innerHTML = ObjectTR.TDs[x].Data;
}
//recalculate row background colours
this.Alternate(tbl);
}//null if
}
function __TableRender()
{
var content = "";
content += "\n<table id=\"datatable_tbl_" + this.ID + "\" cellspacing=\"" + this.Cellspacing + "\" cellpadding=\"" + this.Cellpadding + "\" border=\"" + this.Border + "\"";
if (this.Width != "")
content += " width=\"" + this.Width + "\"";
if (this.Class != "")
content += " class=\"" + this.Class + "\"";
content += ">\n";
for (var x = 0; x < this.TRs.length; x++)
{
if((this.ItemClass != "") && (this.AlternateItemClass != ""))
{
var rowClass = this.ItemClass;
if(x % 2 != 0)
rowClass = this.AlternateItemClass;
content += this.TRs[x].Render(rowClass);
}else
{
if(this.ItemClass != "")
content += this.TRs[x].Render(this.ItemClass);
else
content += this.TRs[x].Render();
}
}
content += "</table>";
return content;
}
function __ChangeClassInRowByIndex(index, Class)
{
var element = Get("datatable_tbl_" + this.ID);
if(element == null)
return;
try
{
var tbody = element.childNodes[0];
var row = tbody.rows[index];
row.className = Class;
}catch(e){}
}
function __TableRowAlternate(objTable)
{
if (this.ItemClass == "" ) return;
if (this.AlternateItemClass == "" ) this.AlternateItemClass = this.ItemClass;
var table = objTable || Get("datatable_tbl_" + this.ID);
if (table == null ) return;
var rows = table.rows;
for(i = 0; i < rows.length; i++)
{
if(i % 2 == 0)
rows[i].className = this.ItemClass;
else
rows[i].className = this.AlternateItemClass;
}
}
}
//***************** End Table Class *******************************//